/**
 * 
 */
package eu.dicodeproject.analysis.xsd.topics;

import java.io.Reader;
import java.io.Writer;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import de.dicodeproject.analysis.xsd.topics.Topics;

/**
 * @author messner@neofonie.de
 * 
 */
public class TopicsUtil {
  private static final JAXBContext jaxbContext;

  static {
    try {
      jaxbContext = JAXBContext.newInstance(Topics.class.getPackage().getName(), Topics.class.getClassLoader());
    } catch (JAXBException e) {
      throw new Error("JAXB error - is there a JAXB implementation on the Classpath?", e);
    }
  }

  private TopicsUtil() {
    // static only
  }

  public static void marshal(Writer writer, Topics topics) throws JAXBException {
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty("jaxb.formatted.output", true);
    marshaller.marshal(topics, writer);
  }

  public static Topics unmarshal(Reader reader) throws JAXBException {    
    return (Topics) jaxbContext.createUnmarshaller().unmarshal(reader); 
  }

}
